#include "StompedReality/Components/PivotComponent.h"
#include "StompedReality/Core/ComponentConstuctionHelper.h"
#include "StompedReality/Core/Graphics/BasicRenderFunctions.h"
#include "StompedReality/Core/TypeSystem/TypeSystem.h"

CreateRegDummy( PivotComponent );

StompedReality::components::PivotComponent::PivotComponent( ) :
  Component ( )
{
}

StompedReality::components::PivotComponent::~PivotComponent( )
{
}

void StompedReality::components::PivotComponent::Draw( )
{
}

void StompedReality::components::PivotComponent::OnCreation( )
{
  Component::OnCreation( );
  this->m_Translation = StompedReality::Math::Vector2 ( 0, 0 );
  this->m_Rotation = 0.0f;
}

void StompedReality::components::PivotComponent::OnDestruction( )
{
}

void StompedReality::components::PivotComponent::InitializeComponent(
  StompedReality::Core::ComponentConstuctionHelper* constructionHelper )
{
  StompedReality::Graphics::Functions::TranslateRotate* pushFunction =
    new StompedReality::Graphics::Functions::TranslateRotate(
      constructionHelper->GetCurrentJsonValue( ).get( "startTransform", 0 ).asUInt( ), true );
  pushFunction->Translation = this->m_Translation;
  pushFunction->Rotation = this->m_Rotation;

  constructionHelper->AddRenderFunction ( pushFunction );

  constructionHelper->AddRenderFunction( new StompedReality::Graphics::Functions::PopMatrix(
                                           constructionHelper->GetCurrentJsonValue( ).get( "endTransform", 0 ).asUInt( )) );
}

bool StompedReality::components::PivotComponent::ProcessMessage ( StompedReality::Core::Message* msg )
{
  return true;
}

void StompedReality::components::PivotComponent::Update ( )
{
}

int StompedReality::components::PivotComponentReg::registeType( )
{
  return ( int ) ( StompedReality::type_system::TypeSystem::CreateTypeInfo<PivotComponent> ( "PivotComponent" )->
                   addTypeField ( StompedReality::type_system::TypeField ( "translation",
                                                                           &PivotComponent::m_Translation ) )->
                   addTypeField ( StompedReality::type_system::TypeField ( "rotation",
                                                                           &PivotComponent::m_Rotation ) ) );
}

static int typeReg = StompedReality::components::PivotComponentReg::registeType( );
